//
//  PicViewController.m
//  DZZTravel
//
//  Created by 赵国栋 on 16/7/17.
//  Copyright © 2016年 Eason. All rights reserved.
//


#import "PicViewController.h"

@interface PicViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic ,strong)UICollectionView *collection;


@property (nonatomic ,strong)NSMutableArray *array;
@end

@implementation PicViewController

{
    NSInteger teger;
}
- (NSMutableArray *)array{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}
- (void)viewDidLoad {
        [super viewDidLoad];
    [self creatCollectView];
    [self creatCell];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage  new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.view.backgroundColor = [UIColor blackColor];
    
    
    
  
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)creatCell{
    
    [RequestManager fectDataWithUrl:[NSString stringWithFormat:@"http://apiphp.yaochufa.com/portal/scenic/ScenicDetail430?channel=AppStore&id=%@&imei=3BB694A0-037E-406A-8F2B-0852448416B6&lang=app&machineCode=3BB694A0-037E-406A-8F2B-0852448416B6&machineType=0&system=ios&version=5.2.3",self.cityID] parameter:@{} method:@"GET" compelet:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        
        NSMutableArray *array =dic[@"content"][@"photoAlbum"];
        for (NSDictionary *dicc in array) {
            [self.array addObject:dicc[@"file"]];
        }
        
    } upDateUI:^{
        [self.collection reloadData];
        
    }];

    
    
}



- (void)creatCollectView{
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    flow.itemSize = CGSizeMake(kWidth, 200);
    self.collection =[[UICollectionView alloc]initWithFrame:CGRectMake(0, kheight/3, kWidth, kheight/3) collectionViewLayout:flow];
    flow.scrollDirection =  UICollectionViewScrollDirectionHorizontal;
    [self.collection registerClass:[PicCollectionViewCell class] forCellWithReuseIdentifier:@"PicCollectionViewCell"];

    self.collection.pagingEnabled = YES;
    
    
    self.collection.delegate  = self;
    self.collection.dataSource = self;
    [self.view addSubview:self.collection];
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  
    
    return self.array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    PicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PicCollectionViewCell" forIndexPath:indexPath];

      [cell.image sd_setImageWithURL:self.array[indexPath.row]];
   

    return cell;
}



- (IBAction)outAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}





@end
